#include "unp.h"
void dg_echo(int, SA*, socklen_t);
int main(int argc, char **argv) {
	int sockfd;
	struct sockaddr_in servaddr, clientaddr;
	sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(9999);
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	Bind(sockfd, (SA*)&servaddr, sizeof(servaddr));
	dg_echo(sockfd, (SA*)&clientaddr, sizeof(clientaddr));
}

void dg_echo(int sockfd, SA *pclientaddr, socklen_t clientlen) {
	int n;
	socklen_t len;
	char msg[MAXLINE];
	for (;;) {
		len  = clientlen;
		n = Recvfrom(sockfd, msg, MAXLINE, 0, pclientaddr, &len);
		Sendto(sockfd, msg, n, 0, pclientaddr, len);
	}
}
